public class Solution209 {
    public int minSubArrayLen(int target, int[] nums) {
        int start=0,sum=0;
        while (sum<target && start<nums.length){
            sum+=nums[start];
            start++;
        }
        if (sum<target){
            return 0;
        }
        int ans=start,j=0;
        for (int i=start-1;i<nums.length;i++){
            if (i>=start){
                sum=sum+nums[i];
            }
            while (j<nums.length && sum>=target){
                sum-=nums[j];
                j++;
            }
            ans=Math.min(ans,i-j+2);
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution209().minSubArrayLen(11,new int[]{1,2,3,4,5}));
    }
}
